package com.bright.ghj.overt.manager.impl;

import com.bright.ghj.overt.manager.EncryptManager;
import lombok.RequiredArgsConstructor;
import org.apache.commons.codec.binary.Base64;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;

/**
 * @Author hxj
 * @Date 2024/3/4 16:04
 * @Description
 */
@Component
@RequiredArgsConstructor
@Qualifier("base64Encrypt")
public class Base64EncryptManagerImpl implements EncryptManager {


    @Override
    public String encrypt(String contentBeforeEncrypt) {
        return Base64.encodeBase64String(contentBeforeEncrypt.getBytes(StandardCharsets.UTF_8));
    }

    @Override
    public String decrypt(String contentBeforeDecrypt) {
        byte[] bytes = Base64.decodeBase64(contentBeforeDecrypt);
        return new String(bytes, StandardCharsets.UTF_8);
    }
}
